package com.hien.adapter;

import com.hien.starting.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class GridViewAdapter extends BaseAdapter {
    private Context context;
    private String[] itemsList;
    private int[] imgResources;

    public GridViewAdapter(Context context, String[] itemList,
	    int[] imgResources) {
	this.context = context;
	this.itemsList = itemList;
	this.imgResources = imgResources;
    }

    public GridViewAdapter(Context context) {
	itemsList = new String[0];
	imgResources = new int[0];
	this.context = context;
    }

    @Override
    public int getCount() {
	return itemsList.length;
    }

    @Override
    public Object getItem(int position) {
	return null;
    }

    @Override
    public long getItemId(int position) {
	return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parents) {
	Holder holder;
	if (convertView == null) {
	    holder = new Holder();
	    LayoutInflater inflater = (LayoutInflater) context
		    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	    convertView = inflater.inflate(R.layout.grid_view_icon, null);
	    holder.img = (ImageView) convertView
		    .findViewById(R.id.img_home_icon);
	    holder.tv = (TextView) convertView.findViewById(R.id.tv_icon_name);
	    convertView.setTag(holder);
	} else {
	    holder = (Holder) convertView.getTag();
	}
	holder.img.setBackgroundResource(imgResources[position]);
	holder.tv.setText(itemsList[position]);
	return convertView;
    }

    class Holder {
	ImageView img;
	TextView tv;
    }
}
